﻿using System;
using System.Windows.Controls;
using LukasKopenec.LocalizationSupport;
using Notoric.Gui.Windows;

namespace Notoric.Gui.Commands
{
    /// <summary>
    /// Implements a command for launching the <see cref="PageAppearanceDialog"/>.
    /// </summary>
    public class PageAppearanceLauncherCommand : RibbonCommand
    {
        #region Constructors

        /// <summary>
        /// Creates a new <see cref="PageAppearanceLauncherCommand"/> instance.
        /// </summary>
        /// <param name="mainWindow">
        /// <para>
        /// Type: <see cref="MainWindow"/>
        /// </para>
        /// <para>
        /// A reference to the main application window.
        /// </para>
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="mainWindow"/> is <see langword="null"/>.
        /// </exception>
        public PageAppearanceLauncherCommand(MainWindow mainWindow)
            : base(mainWindow)
        {
            mainWindow.DocumentPane.SelectionChanged += new SelectionChangedEventHandler(DocumentPane_SelectionChanged);

            ScreenTipTitle = (string)LocalizationManager.GetValue("Ribbon.CommandToolTips.PageAppearance");
            ScreenTipText = (string)LocalizationManager.GetValue("Ribbon.CommandToolTips.PageAppearance.Text");
        }

        #endregion

        #region ICommand Members

        /// <inheritdoc/>
        public override bool CanExecute(object parameter)
        {
            return ApplicationWindow.ActivePage != null;
        }

        /// <inheritdoc/>
        public override void Execute(object parameter)
        {
            var dialog = new PageAppearanceDialog()
            {
                Page = ApplicationWindow.ActivePage
            };
            dialog.ShowDialog();
        }

        #endregion

        #region Event Handlers

        /// <summary>
        /// Occurs when the selected document has changed.
        /// </summary>
        /// <param name="sender">Object where the event handler is attached</param>
        /// <param name="e">Event data</param>
        void DocumentPane_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            RaiseCanExecuteChanged();
        }

        #endregion
    }
}
